import dt from '@dt/dt'
import Opt from '@/components/dt/info/Opt.js'
import table from '@/components/dt/table/render.js'

let _this = null
class Column extends Opt {

  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)

  }
  /*
   * button类型type:1查看详情、2编辑、3发送、4取消发送、5重新发送,
   * status状态:1.未发送/保存 2.已发送 3.发送中 4.发送失败 5.已取消,
   * sendFlag时效类型：1.实时 2.定时
   */
  setButton(type, status, sendFlag) {
    if (status == '2' || status == '3') {
      if (type == 1) {
        return true
      } else {
        return false
      }
    }
    if (status == '4') {
      if (type == 1 || type == 2 || type == 5) {
        return true
      } else {
        return false
      }
    }
    if (status == '1') {
      if (sendFlag == 1) {
        if (type == 1 || type == 2 || type == 3 || type == 4) {
          return true
        } else {
          return false
        }
      } else {
        if (type == 1 || type == 2 || type == 4) {
          return true
        } else {
          return false
        }
      }
    }
    if (status == '5') {
      if (type == 1) {
        return true
      } else {
        return false
      }
    }
  }
  createAll() {
    this.all = [{
      field: 'msgTitle',
      title: '消息标题',
      minWidth: 180
    },
    {
      field: 'sendCompany',
      title: '接收公司',
      minWidth: 180
    },
    {
      field: 'peopleAll',
      title: '总人数/已阅/未阅',
      minWidth: 160,
      cell: (row) => {
        return {
          btn: [{
            title: `${row.peopleAll}`,
            event: 'handelReadDetail',
          }]
        }
      }
    },
    {
      field: 'userName',
      title: '创建人',
      minWidth: 100
    },
    {
      field: 'sendTime',
      title: '发送时间',
      minWidth: 150,
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 150,
    },
    {
      field: 'sendFlagTxt',
      title: '时效',
      minWidth: 80,
    },
    {
      field: 'saveState',
      title: '发送状态',
      minWidth: 100,
      cell: {
        value: (row) => dt.dictInfo().__value('msgType', row.saveState),
        text: {}
      }
    },
    {
      title: '操作',
      minWidth: 200,
      fixed: 'right',
      cell: (row) => {
        return {
          btn: [{
            title: '查看详情',
            event: 'onCheck',
            visible: this.setButton(1, row.saveState, row.sendFlag)
          }, {
            title: '编辑',
            event: 'onEdit',
            visible: this.setButton(2, row.saveState, row.sendFlag)
          }, {
            title: '发送',
            event: 'onSend',
            visible: this.setButton(3, row.saveState, row.sendFlag),
          }, {
            title: '取消发送',
            event: 'cancelSend',
            visible: this.setButton(4, row.saveState, row.sendFlag)
          }, {
            title: '重新发送',
            event: 'againSend',
            visible: this.setButton(5, row.saveState, row.sendFlag),
          }]
        }
      }
    }]
  }
}

export default Column